import 'package:flutter/material.dart';
import 'package:meePet/utils/ext/SizeExt.dart';
import 'package:meePet/utils/ext/StringExt.dart';

import '../../../app/LocalColor.dart';
import '../../../bean/RolePageData.dart';

class OfficialItem {
  bool lockStyleShow = false; //方便查看效果，控制显示解锁效果

  Widget getLeftRoleView(RoleData roleData) {
    return Container(
      width: 335.sw(),
      height: 215.sw(),
      clipBehavior: Clip.antiAlias,
      decoration: BoxDecoration(
          color: LocalColor.color_FF22212F,
          borderRadius: BorderRadius.all(Radius.circular(16.sw()))),
      child: Stack(
        alignment: Alignment.topLeft,
        children: [
          Align(
              alignment: Alignment.topLeft,
              heightFactor: 1.0,
              child: roleData.coverUrl
                  .orEmpty()
                  .loadImage(w: 211.sw(), h: 215.sw(), fit: BoxFit.fitHeight)),
          Align(
            alignment: Alignment.topRight,
            heightFactor: 1.0,
            child: Transform.scale(
              scaleX: -1,
              child: "img_role_cover".webp().loadImageRes(278.sw(), 215.sw()),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 22.sw(), left: 110.sw()),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text(
                      "${roleData.nickname}",
                      style: TextStyle(
                          color: LocalColor.colorWhite,
                          fontSize: 19.sp(),
                          fontWeight: FontWeight.bold),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 5.sw()),
                      child: (roleData.sex == 1)
                          ? ("icon_gender_boy"
                              .png()
                              .loadImageRes(19.sw(), 19.sw()))
                          : ("icon_gender_girl"
                              .png()
                              .loadImageRes(19.sw(), 19.sw())),
                    ),
                    Expanded(
                        child: Container(
                      alignment: Alignment.topRight,
                      margin: EdgeInsets.only(right: 15.sw()),
                      child: Text(
                        "${roleData.chattedUsers}次聊过",
                        style: TextStyle(
                            color: LocalColor.color_FF6564A3,
                            fontSize: 12.sp()),
                        maxLines: 1,
                      ),
                    )),
                  ],
                ),
                Container(
                  margin: EdgeInsets.only(top: 5.sw(), right: 15.sw()),
                  child: Text(
                    "${roleData.tags?.orEmpty()}",
                    style: TextStyle(
                        color: LocalColor.color_FF999999, fontSize: 12.sp()),
                    maxLines: 1,
                    textAlign: TextAlign.justify,
                    overflow: TextOverflow.clip,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 5.sw(), right: 15.sw()),
                  height: 72.sw(),
                  child: Text(
                    "${roleData.description?.orEmpty()}",
                    style: TextStyle(
                      color: LocalColor.colorWhite80,
                      fontSize: 13.sp(),
                    ),
                    maxLines: 4,
                    textAlign: TextAlign.justify,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 5.sw(), right: 15.sw()),
                  child: _getBtnBar(roleData),
                ),
              ],
            ),
          ),
          Container(
            alignment: Alignment.centerLeft,
            margin: EdgeInsets.only(left: 28.sw()),
            child: (roleData.isLock == lockStyleShow
                ? ("ic_unlock_role2".png().loadImageRes(46.sw(), 46.sw()))
                : Container()),
          ),
          SizedBox(
              width: 335.sw(),
              height: 215.sw(),
              child: DecoratedBox(
                decoration: BoxDecoration(
                    color: (roleData.isLock == lockStyleShow
                        ? LocalColor.colorBlack40
                        : LocalColor.colorTranslation)),
              )),
        ],
      ),
    );
  }

  Widget _getBtnBar(RoleData roleData) {
    return Container(
      margin: EdgeInsets.only(top: 12.sw()),
      height: 42.sw(),
      child: (roleData.appearNovel == null && roleData.appearStory == null)
          ? Container(
              child: (roleData.sex == 1 ? "bg_chat_boy3" : "bg_chat_girl3")
                  .webp()
                  .loadImageRes(198.sw(), 42.sw()),
            )
          : Row(
              children: [
                Container(
                    margin: EdgeInsets.only(right: 1.sw()),
                    child:
                        (roleData.sex == 1 ? "bg_chat_boy2" : "bg_chat_girl2")
                            .webp()
                            .loadImageRes(104.sw(), 42.sw())),
                Container(
                    margin: EdgeInsets.only(left: 1.sw()),
                    child: (roleData.appearStory != null
                            ? "btn_ai_story.png"
                            : "ic_heart_beat_play.webp")
                        .img()
                        .loadImageRes(104.sw(), 42.sw())),
              ],
            ),
    );
  }

  Widget getRightRoleView(RoleData roleData) {
    return Container(
      width: 335.sw(),
      height: 215.sw(),
      clipBehavior: Clip.antiAlias,
      decoration: BoxDecoration(
          color: LocalColor.color_FF22212F,
          borderRadius: BorderRadius.all(Radius.circular(16.sw()))),
      child: Stack(
        alignment: Alignment.topRight,
        children: [
          Transform.scale(
            scaleX: -1,
            child: Align(
                alignment: Alignment.topLeft,
                heightFactor: 1.0,
                child: roleData.coverUrl.orEmpty().loadImage(
                    w: 211.sw(), h: 215.sw(), fit: BoxFit.fitHeight)),
          ),
          Align(
            alignment: Alignment.topLeft,
            heightFactor: 1.0,
            child: "img_role_cover".webp().loadImageRes(278.sw(), 215.sw()),
          ),
          Container(
            margin: EdgeInsets.only(top: 22.sw(), left: 15.sw()),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text(
                      "${roleData.nickname}",
                      style: TextStyle(
                          color: LocalColor.colorWhite,
                          fontSize: 19.sp(),
                          fontWeight: FontWeight.bold),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 5.sw()),
                      child: (roleData.sex == 1)
                          ? ("icon_gender_boy"
                              .png()
                              .loadImageRes(19.sw(), 19.sw()))
                          : ("icon_gender_girl"
                              .png()
                              .loadImageRes(19.sw(), 19.sw())),
                    ),
                    Expanded(
                        child: Container(
                      alignment: Alignment.centerRight,
                      margin: EdgeInsets.only(right: 120.sw()),
                      child: Text(
                        "${roleData.chattedUsers}次聊过",
                        style: TextStyle(
                            color: LocalColor.color_FF6564A3,
                            fontSize: 12.sp()),
                        maxLines: 1,
                      ),
                    )),
                  ],
                ),
                Container(
                  margin: EdgeInsets.only(top: 5.sw(), right: 15.sw()),
                  child: Text(
                    "${roleData.tags?.orEmpty()}",
                    style: TextStyle(
                        color: LocalColor.color_FF999999, fontSize: 12.sp()),
                    maxLines: 1,
                    textAlign: TextAlign.justify,
                    overflow: TextOverflow.clip,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 5.sw(), right: 120.sw()),
                  height: 72.sw(),
                  child: Text(
                    "${roleData.description?.orEmpty()}",
                    style: TextStyle(
                      color: LocalColor.colorWhite80,
                      fontSize: 13.sp(),
                    ),
                    maxLines: 4,
                    textAlign: TextAlign.justify,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 5.sw(), right: 15.sw()),
                  child: _getBtnBar(roleData),
                ),
              ],
            ),
          ),
          Container(
            alignment: Alignment.centerRight,
            margin: EdgeInsets.only(right: 28.sw()),
            child: (roleData.isLock == lockStyleShow
                ? ("ic_unlock_role2".png().loadImageRes(46.sw(), 46.sw()))
                : Container()),
          ),
          SizedBox(
              width: 335.sw(),
              height: 215.sw(),
              child: DecoratedBox(
                decoration: BoxDecoration(
                    color: (roleData.isLock == lockStyleShow
                        ? LocalColor.colorBlack40
                        : LocalColor.colorTranslation)),
              )),
        ],
      ),
    );
  }
}
